//
//  LYTeacherCell.m
//  artist
//
//  Created by Jay_Apple on 16/4/13.
//  Copyright © 2016年 viviyoo. All rights reserved.
//

#import "LYTeacherCell.h"


@interface LYTeacherCell ()

@property (weak, nonatomic) IBOutlet UIImageView *Icon;

@property (weak, nonatomic) IBOutlet UILabel *name;

@property (weak, nonatomic) IBOutlet UIImageView *sexIcon;

@property (weak, nonatomic) IBOutlet UIView *starView;

@property (weak, nonatomic) IBOutlet UILabel *content;

@property (weak, nonatomic) IBOutlet UILabel *address;

@property (weak, nonatomic) IBOutlet UIButton *distance;

@property (weak, nonatomic) IBOutlet UIButton *cancelFollowBtn;


@end

@implementation LYTeacherCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setModel:(LYPersonalInfo *)model{
    
    _model = model;
    //头像
    [self.Icon sd_setImageWithURL:[NSURL URLWithString:_model.head_pic] placeholderImage:[UIImage imageNamed:@"contacts_default_avatar"]];
    //名字
    self.name.text = _model.nick_name;
    //课程
    self.content.text = _model.major;
    //地址
    
    NSString *address = [NSString stringWithFormat:@"%@%@%@",_model.province,_model.city,_model.area];
    self.address.text = address;
    
    //距离
    CGFloat distance = [_model.distinct doubleValue];
    
    NSString *distanceStr = [NSString stringWithFormat:@"%.1fkm",distance];
    [self.distance setTitle:distanceStr forState:UIControlStateNormal];
    
    //性别
    switch (_model.sex) {
        case SEXNone:
            
            self.sexIcon.hidden = YES;
            
            break;
            
        case SEXMan:
            
            self.sexIcon.hidden = NO;
            self.sexIcon.image = [UIImage imageNamed:@"男性"];
            
            break;
        case SEXWoman:
            
            self.sexIcon.hidden = NO;
            self.sexIcon.image = [UIImage imageNamed:@"女性"];
            
            break;
    }
    
    //星星
    for (NSInteger i = 0; i < 5; i++) {
        
        UIImageView *imageV = self.starView.subviews[i];
        if (i < _model.star) {
            imageV.image = [UIImage imageNamed:@"全星"];
        }else{
            imageV.image = [UIImage imageNamed:@"空星"];
        }
        
    }
    
    //取消关注按钮
    self.cancelFollowBtn.hidden = !_model.showCancelFollowBtn;
    
}

/**
 *  取消关注
 */
- (IBAction)cancelBtnOnclick:(id)sender {
    
    if ([self.delegate respondsToSelector:@selector(cellCancelBtnOnclick:)]) {
        [self.delegate cellCancelBtnOnclick:self];
    }
    
}


@end
